﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RBAC;

namespace RBAC.Administry.Account
{
    public partial class Add : System.Web.UI.Page
    {
        #region page logic

        private void Submit()
        {
            try
            {
                RBAC.Account account = ParseInput();
                account.Add();
                account.Save();

                PageHelper.Script(this, "done();", UpdatePanel1);
            }
            catch(AccessControlException e)
            {
                PageHelper.Error(this, e.Message, UpdatePanel1);
            }
        }

        private RBAC.Account ParseInput()
        {
            return new RBAC.Account
            {
                ID = this.id.Text,
                Display = this.display.Text,
                Password = RBAC.Account.DefaultPassword
            };
        }


        #endregion

        #region event processing

        protected void submit_Click(object sender, EventArgs e)
        {
            Submit();
        }

        #endregion

    }
}
